import {UPDATE_INVEST_SHOW_LIST, LOAD_INVEST_SHOW_LIST} from '../actions'

export default function investShowReducer(state = {}, action) {
    const {list} = action
    //give uid for list item
    switch (action.type) {
        case UPDATE_INVEST_SHOW_LIST:
            const listItems = {}
            list && list.data && list
                .data
                .map((item) => listItems[item.id] = item);
            listItems = {
                ...state.list,
                ...listItems
            }
            listItems.length = 0
            for (let k in listItems) {
                listItems.hasOwnProperty(k) && k !== 'length' && listItems.length++
            }
            return {
                ...state,
                list: listItems,
                data: {...list}
            }
        default:
            return state
    }
}